﻿Public Class Registro
    Dim rs As ADODB.Recordset
    Dim sql As String
    Dim codigo As Integer = 0
    Private Sub btnAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAceptar.Click
        Try
            sql = "INSERT INTO `CLIENTE` (`CODI_CLIEN`, `NOMB_CLIEN`, `PATE_CLIEN`, `MATE_CLIEN`, `FENA_CLIEN`, `SEXO_CLIEN`, `TELF_CLIEN`, `DIRE_CLIEN`, `DNI_CLIEN`, `FERE_CLIEN`) VALUES ('" & txtCodigo.Text & "', '" & txtNombre.Text & "', '" & txtAPaterno.Text & "', '" & txtAMaterno.Text & "', '" & DateFechaN.Value.ToString & "', '" & CmbSExo.SelectedItem.ToString & "', '" & txtTelefono.Text & "', '" & txtDireccion.Text & "', '" & txtDNI.Text & "', '" & DateFEchaRegistro.Value.ToString & "')"
            rs = coneccion.Execute(sql)
        Catch ex As Exception
            MsgBox("El Usuario ya Existe", MsgBoxStyle.Exclamation)
        End Try
        Me.Dispose()

    End Sub

    Private Sub btnLimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLimpiar.Click
        txtNombre.Text = ""
        txtAPaterno.Text = ""
        txtAMaterno.Text = ""
        txtDireccion.Text = ""
        txtDNI.Text = ""
        txtTelefono.Text = ""

    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Dispose()
    End Sub

    Private Sub Registro_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        conectar()
        sql = "SELECT MAX(CODI_CLIEN) FROM CLIENTE"
        rs = coneccion.Execute(sql)
        If CInt(rs.Fields(0).Value) <> 0 Then
            codigo = CInt(rs.Fields(0).Value) + 1
        Else
            codigo = 10000
        End If
        txtCodigo.Text = codigo.ToString
        Console.WriteLine(codigo)
    End Sub
End Class